import { Game, GameComponent } from "@sapi-game/main";
import { eleBackState } from "./state";

export class ElevatorBackActionBar extends GameComponent<eleBackState> {
    override onAttach(): void {
        this.subscribe(Game.events.interval, this.showActionBar.bind(this));
    }

    showActionBar() {
        const players = this.state.cat
            .getAll()
            .concat(this.state.mouse.getAll());
        const catCount = this.state.cat.validSize;
        const mouseCount = this.state.mouse.size;

        let text: string;

        if (this.state.getTotalPlayers() >= 2) {
            text = `§b猫猫队：${catCount} §a躲躲队: ${mouseCount} §7| §e等待开始...`;
        } else {
            text = `§b猫猫队：${catCount} §a躲躲队: ${mouseCount} §7| §e等待中...`;
        }

        players.forEach((p) => p.actionbar(text));
    }
}
